package cn.itcast.wanxinp2p.consumer.service.iml;

import cn.itcast.wanxinp2p.api.consumer.model.BankCardDTO;
import cn.itcast.wanxinp2p.api.depository.model.ConsumerRequest;
import cn.itcast.wanxinp2p.api.depository.model.GatewayRequest;
import cn.itcast.wanxinp2p.common.domain.RestResponse;
import cn.itcast.wanxinp2p.consumer.entity.BankCard;
import cn.itcast.wanxinp2p.consumer.mapper.BankCardMapper;
import cn.itcast.wanxinp2p.consumer.service.BankCardService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> implements BankCardService {

   @Override
   public BankCardDTO getByConsumerId(Long consumerId) {
      BankCard bankCard = getOne(new QueryWrapper<BankCard>().lambda()
                                 .eq(BankCard::getConsumerId, consumerId));
      System.out.println("我在fenzhi1添加了这段话"+ LocalDateTime.now());
      System.out.println("我在fenzhi-dev添加了这段话"+ LocalDateTime.now());
      return convertBankCardEntityToDTO(bankCard);

   }

   @Override
   public BankCardDTO getByCardNumber(String cardNumber) {
      BankCard bankCard = getOne(new QueryWrapper<BankCard>().lambda()
                                 .eq(BankCard::getCardNumber, cardNumber));
      return convertBankCardEntityToDTO(bankCard);
   }
//restore workspace on branch switching
   //show notification with ability to restore previous workspace
   /*
   * 生成开户数据*/
   @Override
   public RestResponse<GatewayRequest> createConsumer(ConsumerRequest consumerRequest) {

      //根据用户手机号查询用户信息

      //判断用户是否已经开户

      //判断银行卡号是否已经被绑定

      //更新用户开户信息

      //产生请求流水号和用户编号

      //

      //




      return null;
   }

   /**
    * entity转为dto
    * @param entity
    * @return
    */
   private BankCardDTO convertBankCardEntityToDTO(BankCard entity) {
      if (entity == null) {
         return null;
      }
      BankCardDTO dto = new BankCardDTO();
      BeanUtils.copyProperties(entity, dto);
      return dto;
   }
}